package oocl.ita.eordering.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import oocl.ita.eordering.po.Merchant;
import oocl.ita.eordering.po.ResponsePo;
import oocl.ita.eordering.service.FoodService;
import oocl.ita.eordering.service.MerchantService;

@Controller
@RequestMapping("/homes")
public class UploadifiveController {
	@Autowired
	private MerchantService ms;
	@Autowired
	private FoodService fs;

	@RequestMapping("/uploadi5")
	@ResponseBody
	public ResponsePo uploadifive( MultipartFile pic,HttpServletRequest request) throws Exception {
		ResponsePo fileUploadPo=new ResponsePo();
		String mTel=null;
		String picKind =request.getParameter("picKind");
		System.out.println("originalName"+"....."+pic.getOriginalFilename());
		System.out.println("文件已上传"+"....."+picKind);
		if(picKind.equals("fViewPath")){
			System.out.println(1);
			mTel=((Merchant)(request.getSession().getAttribute("user"))).getmTel();
			String fViewPath=fs.getFoodViewPath(mTel, pic);
			request.getSession().setAttribute("fViewPath", fViewPath);
		} else if (picKind.equals("mCardPath")){
			mTel=request.getParameter("mTel");
			String mCardPath=ms.getIdCardPath(mTel, pic);
			request.getSession().setAttribute("mCardPath", mCardPath);
		}else {
			mTel=request.getParameter("mTel");
			String mLogoPath=ms.getLogoPath(mTel, pic);
			request.getSession().setAttribute("mLogoPath", mLogoPath);
		}
		fileUploadPo.setStatus(true);
		return fileUploadPo;
	}
	
	
	@RequestMapping("/getSessionAttr")
	@ResponseBody
	public String  getSessionAttr(HttpServletRequest request) throws Exception {
		String senssionAttr =request.getParameter("senssionAttr");
		String senssionAttr2=(String)(request.getSession().getAttribute(senssionAttr));
		System.out.println("文件已上传"+"....."+senssionAttr2);
		
		return senssionAttr2;
	}

}
